package fr.web325.servlet.api.cart;

import fr.web325.bean.Json;
import fr.web325.dao.ClientDao;
import net.sf.json.JSONArray;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

@WebServlet("/api/payOrder")
public class PayOrder extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 通过订单ID获取已提交的信息返回到order.jsp
        String order_id =  req.getParameter("orderId");
        try {
            List<Map<String,Object>> orderItem = new ClientDao().getOrderItem(order_id);
            if(orderItem == null){
                resp.getWriter().print(new Json(202,null,"请检查订单号是否正确").getRespJson());
                return;
            }
            JSONArray orderJson = JSONArray.fromObject(orderItem);
            resp.getWriter().print(new Json(200,orderJson,"获取订单详情成功").getRespJson());
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
